﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class 数据算法_直插入排序_增量法_ : System.Web.UI.Page
{
    int x;
    protected void Page_Load(object sender, EventArgs e)
    {
        int[] a = {4336, 4, 65, 45, 4548, 5498979, 4656, 44, 4336, 7863 };
        SelectSort(a);
    }

    public void SelectSort(int[] arr)  //直接选择排序   
    {
        int i, j, min, change = 0, loop = 0;
        for (i = 0; i < arr.Length - 1; i++)
        {
            min = i;
            for (j = i + 1; j < arr.Length; j++)
            {
                if (arr[j] < arr[min])     //此处改为">"则从大到小排列    
                    min = j;
            }
            x = arr[min];
            arr[min] = arr[i];
            arr[i] = x;
            
            change++;
            loop++;

        }
          string  strx = "";
        foreach (int csd in arr)
        {
           strx +=csd.ToString()+",";
        }

        Response.Write("本次排序交换" + change + "次,循环" + loop + "次n 結果：" + strx);


    }


}
